#!/usr/bin/perl 
# undef.pl
use warnings;
use strict;

# get a filename
my $file = $ARGV[0] or die "Usage $0 <result file> \n";

# process and return result
my $result = get_results($file);

# test result
if ($result) {
   print "Result of computation on '$file' is $result \n";
} elsif (defined $result) {
   print "No results found in file \n";
} else {
   print "Error - could not open file: $! \n";
}

# and the subroutine...
sub get_results {
   # return 'undef' to indicate error
   open RESULTS, $_[0] or return undef;

   # compute result (simple sum)
   my $file_result = 0;
   while (<RESULTS>) {
      $file_result += $_;
   }
	
   # return result, 0 if file empty
   return $file_result;
}